extends IEventActuator


class_name AttibuteActuator
"""
以Attribute值触发单个事件
"""


## 属性名称
@export var attr_name: String = ""
## 角色
@export var character: ICharacterComponent = null
## 需要触发的事件列表
@export var event_actuators: Array[IEventActuator] = []


func __check_exports() -> Dictionary:
    return IComponent.merge({
        "character": IComponent.find_up.bind(self, func(x): return x is ICharacterComponent, character),
        "event_actuators": IComponent.find_children.bind(self, func(x): return x is IEventActuator, event_actuators),
    }, super.__check_exports())

func execute() -> void:
    var attr: Attribute = character.get_attribute(attr_name)
    if attr and attr.value >= 0 and attr.value < event_actuators.size():
        IEventActuator.safe_execute(event_actuators[attr.value])
